/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mavenrentcars.dao.hibernate;

import com.mavenrentcars.dao.AccountDao;
import com.mavenrentcars.model.User;
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

/**
 *
 * @author dkozyrev
 */
@Repository("accountDao")
public class AccountDaoHibernate extends GenericDaoHibernate<User, Integer> implements AccountDao {

    @Autowired
    public AccountDaoHibernate(@Qualifier("sessionFactory") SessionFactory sessionFactory) {
        super(User.class);
        setSessionFactory(sessionFactory);
    }

    @Override
    public User getAccountByLogin(String login) {
        List<User> res = this.getHibernateTemplate().find(
                "from " + User.class.getName()
                + " obj where obj.email = ?",
                login);
        if (res.isEmpty()) {
            return null;
        }

        return res.get(0);
    }
}
